home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INSTALL / program files / Borland / Delphi6 / Lib / DdeReg.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-22  |  9KB  |  347 lines

  1. unit DdeReg;
  2.  
  3. interface
  4.  
  5. uses Windows, SysUtils, Classes, Graphics, Forms, Controls, Buttons, TypInfo,
  6.   DesignIntf, DesignEditors, DdeMan, Messages, StdCtrls, ExtCtrls;
  7.  
  8. {  TComponentEditors }
  9.  
  10. type
  11.   TSrvrConvEdit = class(TDefaultEditor)
  12.   protected
  13.     procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
  14.   end;
  15.  
  16.   TCliConvEdit = class(TDefaultEditor)
  17.   protected
  18.     procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
  19.   end;
  20.  
  21.   TSrvrItemEdit = class(TDefaultEditor)
  22.   public
  23.     procedure Copy; override;
  24.   end;
  25.  
  26.  
  27. {  TForms }
  28. type
  29.   TDdeLinkDlg = class(TForm)
  30.     TopicEdit: TEdit;
  31.     AppEdit: TEdit;
  32.     Label1: TLabel;
  33.     Label2: TLabel;
  34.     OK: TButton;
  35.     CancelBtn: TButton;
  36.     PasteBtn: TButton;
  37.     HelpBtn: TButton;
  38.     procedure doPasteLink(Sender: TObject);
  39.     procedure DoPasteCheck(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure HelpBtnClick(Sender: TObject);
  42.   private
  43.     procedure WMActivate(var Message: TWMActivate); message WM_ACTIVATE;
  44.   end;
  45.  
  46.  
  47.   TDdeLinkInfoProperty = class(TPropertyEditor)
  48.   public
  49.     function GetAttributes: TPropertyAttributes; override;
  50.     procedure Edit; override;
  51.     function  GetValue: string; override;
  52.   end;
  53.  
  54.   TDdeClientItemProperty = class(TStringProperty)
  55.   public
  56.     function GetAttributes: TPropertyAttributes; override;
  57.     procedure GetValues(Proc: TGetStrProc); override;
  58.   end;
  59.  
  60. procedure Register;
  61.  
  62. implementation
  63.  
  64. uses Dialogs, LibHelp, ExptIntf, ToolIntf, EditIntf, DsnConst;
  65.  
  66. {$R *.dfm}
  67. {---------------------------------------}
  68.  
  69. procedure TSrvrConvEdit.EditProperty(const Prop: IProperty; var Continue: Boolean);
  70. var
  71.   PropName: string;
  72. begin
  73.   PropName := Prop.GetName;
  74.   if (CompareText(PropName, 'ONEXECUTEMACRO') = 0) then
  75.   begin
  76.     Prop.Edit;
  77.     Continue := False;
  78.   end
  79.   else
  80.     inherited EditProperty(Prop, Continue);
  81. end;
  82.  
  83.  
  84. procedure TCliConvEdit.EditProperty(const Prop: IProperty; var Continue: Boolean);
  85. var
  86.   PropName: string;
  87. begin
  88.   PropName := Prop.GetName;
  89.   if (CompareText(PropName, 'ONOPEN') = 0) then
  90.   begin
  91.     Prop.Edit;
  92.     Continue := False;
  93.   end
  94.   else
  95.     inherited EditProperty(Prop, Continue);
  96. end;
  97.  
  98. procedure TSrvrItemEdit.Copy;
  99. begin
  100.   TDdeServerItem(Component).CopyToClipboard;
  101. end;
  102.  
  103.  
  104. {---------------------------------------}
  105. { TDdeLinkInfoProperty }
  106.  
  107. function TDdeLinkInfoProperty.GetAttributes: TPropertyAttributes;
  108. begin
  109.   Result := inherited GetAttributes + [paDialog, paReadOnly]
  110.                       - [paMultiSelect, paSubProperties];
  111. end;
  112.  
  113. function TDdeLinkInfoProperty.GetValue: string;
  114. begin
  115.   if GetStrValue = '' then Result := SDdeEmptyConnection
  116.   else Result := Format ('(%s)', [GetStrValue]);
  117. end;
  118.  
  119. procedure TDdeLinkInfoProperty.Edit;
  120. var
  121.   DdeCli      : TDdeClientConv;
  122.   LinkDlg     : TDdeLinkDlg;
  123. begin
  124.   DdeCli := TDdeClientConv (GetComponent(0));
  125.   LinkDlg := TDdeLinkDlg.Create(Application);
  126.   try
  127.     LinkDlg.AppEdit.Text    :=   DdeCli.DdeService;
  128.     LinkDlg.TopicEdit.Text  :=   DdeCli.DdeTopic;
  129.  
  130.     if LinkDlg.ShowModal = idOk then
  131.     begin
  132.       if Not DdeCli.SetLink(LinkDlg.AppEdit.Text,
  133.                             LinkDlg.TopicEdit.Text) then
  134.         MessageDlg(SDdeNoConnect, mtError, [mbOK], 0);
  135.       Modified;
  136.     end;
  137.   finally
  138.     LinkDlg.Free;
  139.   end;
  140. end;
  141.  
  142. {---------------------------------------}
  143.  
  144. procedure TDdeLinkDlg.doPasteLink(Sender: TObject);
  145. var
  146.   Service, Topic, Item : String;
  147. begin
  148.   if  GetPasteLinkInfo (Service, Topic, Item) = True  then
  149.   begin
  150.     AppEdit.Text   := Service;
  151.     TopicEdit.Text := Topic;
  152.   end
  153.   else
  154.   begin
  155.     AppEdit.Text   := EmptyStr;
  156.     TopicEdit.Text := EmptyStr;
  157.   end;
  158. end;
  159.  
  160. procedure TDdeLinkDlg.DoPasteCheck(Sender: TObject);
  161. var
  162.   enable : Boolean;
  163.   Service, Topic, Item : String;
  164. begin
  165.   enable := False;
  166.   if  GetPasteLinkInfo (Service, Topic, Item) = True  then
  167.     enable := True;
  168.   if enable <> PasteBtn.Enabled then
  169.     PasteBtn.Enabled := enable;
  170. end;
  171.  
  172. procedure TDdeLinkDlg.WMActivate(var Message: TWMActivate);
  173. begin
  174.   inherited;
  175.   if Message.Active <> WA_INACTIVE then DoPasteCheck(Self);
  176. end;
  177.  
  178. procedure TDdeLinkDlg.FormCreate(Sender: TObject);
  179. begin
  180.   HelpContext := hcDDDEInfo;
  181. end;
  182.  
  183. procedure TDdeLinkDlg.HelpBtnClick(Sender: TObject);
  184. begin
  185.   Application.HelpContext(HelpContext);
  186. end;
  187.  
  188. {-------}
  189. { TDdeClientItemProperty }
  190.  
  191. function TDdeClientItemProperty.GetAttributes: TPropertyAttributes;
  192. begin
  193.   Result := inherited GetAttributes + [paValueList] - [paMultiSelect,
  194.     paSubProperties];
  195. end;
  196.  
  197. procedure TDdeClientItemProperty.GetValues(Proc: TGetStrProc);
  198. var
  199.   Cli  : TDdeClientConv;
  200.   Service, Topic, Item : String;
  201. begin
  202.   Cli := TDdeClientConv(TDdeClientItem (GetComponent(0)).DdeConv);
  203.   if Cli <> Nil then
  204.   begin
  205.     if  GetPasteLinkInfo (Service, Topic, Item) = True  then
  206.     begin
  207.       if (Service = Cli.DdeService) and
  208.          (Topic = Cli.DdeTopic) then
  209.         Proc (Item);
  210.     end;
  211.   end;
  212. end;
  213.  
  214. type
  215.   TDDEProjectNotifier = class(TIAddInNotifier)
  216.     procedure FileNotification(NotifyCode: TFileNotification;
  217.       const FileName: string; var Cancel: Boolean); override;
  218.     procedure EventNotification(NotifyCode: TEventNotification;
  219.       var Cancel: Boolean); override;
  220.   end;
  221.  
  222.   TDDEModuleNotifier = class(TIModuleNotifier)
  223.   private
  224.     ModuleInterface: TIModuleInterface;
  225.   public
  226.     constructor Create(AModuleInterface: TIModuleInterface);
  227.     destructor Destroy; override;
  228.     procedure Notify(NotifyCode: TNotifyCode); override;
  229.     procedure ComponentRenamed(const AComponent: TComponent;
  230.       const OldName, NewName: string); override;
  231.   end;
  232.  
  233. var
  234.   ProjHooks: TList;
  235.   ProjHook: TDDEProjectNotifier;
  236.  
  237. procedure TDDEProjectNotifier.FileNotification;
  238. var
  239.   MI: TIModuleInterface;
  240.   Hook: TDDEModuleNotifier;
  241. begin
  242. // Per Chuck Allen
  243. {
  244.   case NotifyCode of
  245.     fnProjectOpened:
  246.       begin
  247.         DDEMgr.AppName := ChangeFileExt(ExtractFileName(FileName),'');
  248.         MI := ToolServices.GetModuleInterface(FileName);
  249.         if MI <> nil then
  250.         begin
  251.           Hook := TDDEModuleNotifier.Create(MI);
  252.           ProjHooks.Add(Hook);
  253.           MI.AddNotifier(Hook);
  254.           MI.Release;
  255.         end;
  256.       end;
  257.     fnProjectClosing: DDEMgr.AppName := '';
  258.   end;
  259. }  
  260. end;
  261.  
  262. procedure TDDEProjectNotifier.EventNotification;
  263. begin
  264. end;
  265.  
  266. constructor TDDEModuleNotifier.Create(AModuleInterface: TIModuleInterface);
  267. begin
  268.   inherited Create;
  269.   ModuleInterface := AModuleInterface;
  270.   ModuleInterface.AddRef;
  271. end;
  272.  
  273. destructor TDDEModuleNotifier.Destroy;
  274. begin
  275.   ProjHooks.Remove(Self);
  276.   ModuleInterface.Release;
  277.   inherited Destroy;
  278. end;
  279.  
  280. procedure TDDEModuleNotifier.Notify(NotifyCode: TNotifyCode);
  281. var
  282.   EditInterface: TIEditorInterface;
  283. begin
  284.   case NotifyCode of
  285.     ncModuleDeleted:
  286.       begin
  287.         ModuleInterface.RemoveNotifier(Self);
  288.         Release;
  289.       end;
  290.     ncModuleRenamed:
  291.       begin
  292.         EditInterface := ModuleInterface.GetEditorInterface;
  293.         if EditInterface <> nil then
  294.         try
  295.           DDEMgr.AppName := ChangeFileExt(ExtractFileName(EditInterface.FileName),'');
  296.         finally
  297.           EditInterface.Free;
  298.         end;
  299.       end;
  300.   end;
  301. end;
  302.  
  303. procedure TDDEModuleNotifier.ComponentRenamed(const AComponent: TComponent;
  304.   const OldName, NewName: string);
  305. begin
  306. end;
  307.  
  308. procedure Register;
  309. begin
  310.   RegisterComponents(srSystem, [TDdeClientConv, TDdeClientItem, TDdeServerConv,
  311.     TDdeServerItem]);
  312.   RegisterPropertyEditor(TypeInfo(string), TDdeClientConv, 'DdeService', TDdeLinkInfoProperty);
  313.   RegisterPropertyEditor(TypeInfo(string), TDdeClientConv, 'DdeTopic', TDdeLinkInfoProperty);
  314.   RegisterPropertyEditor(TypeInfo(string), TDdeClientItem, 'DdeItem', TDdeClientItemProperty);
  315.   RegisterComponentEditor(TDdeServerItem, TSrvrItemEdit);
  316.   RegisterComponentEditor(TDdeServerConv, TSrvrConvEdit);
  317.   RegisterComponentEditor(TDdeClientConv, TCliConvEdit);
  318.   RegisterPropertiesInCategory(sLocalizableCategoryName, TDdeServerItem, ['Lines']); { Text property displays Lines[0] }
  319.   RegisterPropertiesInCategory(sLocalizableCategoryName, TDdeClientItem, ['Lines']); { Text property displays Lines[0] }
  320.   ProjHook := TDDEProjectNotifier.Create;
  321.   ToolServices.AddNotifier(ProjHook);
  322. end;
  323.  
  324. procedure FreeProjFileHooks;
  325. var
  326.   I: Integer;
  327. begin
  328.   if (ToolServices = nil) or (ProjHooks = nil) then Exit;
  329.   I := ProjHooks.Count - 1;
  330.   while I > -1 do
  331.   begin
  332.     TDDEModuleNotifier(ProjHooks[I]).Notify(ncModuleDeleted);
  333.     Dec(I);
  334.   end;
  335.   ToolServices.RemoveNotifier(ProjHook);
  336.   ProjHook.Release;
  337.   ProjHook := nil;
  338. end;
  339.  
  340. initialization
  341.   ProjHooks := TList.Create;
  342. finalization
  343.   FreeProjFileHooks;
  344.   ProjHooks.Free;
  345.   ProjHooks := nil;
  346. end.
  347.